<% @nodes = []
eager = [:assigned_vm_address, :strand, :semaphores]

@nodes +=
  @kc.cp_vms(eager:).map do |vm|
    { name: vm.name, role: "Control Plane", state: vm.display_state, hostname: vm.ip4_string }
  end

@nodes +=
  @kc
    .nodepools_dataset
    .eager(vms: eager)
    .all
    .flat_map do |np|
      np.vms.map { |vm| { name: vm.name, role: "Worker", state: vm.display_state, hostname: vm.ip4_string } }
    end %>

<div class="p-6">
  <%== part(
    "components/table_card",
    title: "Nodes",
    headers: %w[Name Role State Hostname],
    empty_state: "This cluster doesn't have any nodes yet",
    rows:
      @nodes.map { |n| [[n[:name], n[:role], n[:state], [n[:hostname], { copyable: true }]], { id: "node-#{n[:name]}" }] }
  ) %>
</div>
